from datetime import date
import os
from mutagen.id3 import ID3, TDRC, TIT2, TALB, TPE1, TCON, APIC
from config import ALBUM_NAME, GENRE
#TODO use pathlib

def modified_id3(file_name: str, artist_name: str, title: str) -> None:
        id3 = ID3()
        id3.add(TIT2(encoding=3, text=title))
        id3.add(TALB(encoding=3, text=ALBUM_NAME))
        id3.add(TPE1(encoding=3, text=artist_name))
        #TODO just year
        id3.add(TDRC(encoding=3, text=str(date.today())))
        id3.add(TCON(encoding=3, text=GENRE))
        cover_path = f"{os.getcwd()}/media/covers/{artist_name}.jpg"
        if not os.path.isfile(cover_path):
            #TODO add to confid name of default cover
            cover_path = f"{os.getcwd()}/media/covers/cover.jpg"
            if not os.path.isfile(cover_path):
                cover_path = f"{os.getcwd()}/media/default_cover.jpg"

        id3.add(
                APIC(encoding=3,
                mime=u'image/jpg',
                type=3,
                desc=u'Cover',
                data=open(cover_path, 'rb').read()))
        
        id3.save(file_name)

